package servlet;

import pagination.PageBean;
import pojo.Brand;
import service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "SelectAllServlet", value = "/selectAll")
public class SelectAllServlet extends HttpServlet {
    //创建一个业务层对象作为属性
    private BrandService brandService = new BrandService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收分页参数（当前是第几页，每一页大小为10个）
        String currentPage = request.getParameter("currentPage");
        int curPage = 1;
        if(currentPage!=null){
            curPage = Integer.valueOf(currentPage);

        }
        int pageSize = 10;

        PageBean<Brand> pageBean = brandService.selectAllPage(curPage,pageSize);

        request.setAttribute("pageBean",pageBean);

        request.getRequestDispatcher("/brand.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}